home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 32
/
Amiga Format AFCD32 (Nov 1998, Issue 117).iso
/
-seriously_amiga-
/
programming
/
basic
/
textreader
/
help.asc
< prev
next >
Wrap
Text File
|
1998-08-10
|
8KB
|
235 lines
;GT text reader
;by Curt Esser
;camge@ix.netcom.com
;last modified March 5,1998
;MUST HAVE amigalibs.res as resident in compiler options!
;--------------------------------------------------------------
WBStartup
NoCli
width.w=640 ;screen width
height.w=400 ;screen height
;--------------SET UP HELP WINDOW VARIABLES--------------------
HelpMe.b=Off ;starts with help window closed
HelpGadgets.b=2 ;0=none,1=cycle only,2=both
NEWTYPE.textEX ;for the word-wrapping stuff
txwidth.w ;this is used as a workspace
txheight.w ;by the Textfit_ command
txMinx.w
txMiny.w
txMaxx.w
txMaxy.w
End NEWTYPE
NEWTYPE.text ;for the GTlistview
pad.w
text.s
End NEWTYPE
al.textEX\txwidth=0,0,0,0,0,0 ;for the word-wrap routine
maxlines=2000 ;must be > maximum lines of text expected
Dim List htxt.text(maxlines) ;for the listview gadget
font$="topaz.font" ;name of the font for the help window
fsize.b=11 ;font height to be used
#HelpWindow=1 ;window number for the help window
help$="GT.help" ;name & path of help text file
helpwide.w=500 ;width of help window
helpheight.w=10 ;height of text window in text lines!
helpx.w=(width/2)-(helpwide/2) ;inital x position for help window
helpy.w=(height/2)-(helpheight*fsize/2) ;initial y position for help window
Dim links.w(50) ;maximum # of index links
Dim lnk$(50) ;string array to store the link labels
helphigh=(helpheight+1)*fsize+9 ;calculate height of help window
lvhigh.w=(helpheight+1)*fsize ;calculate height of listview gadget
hghigh.w=fsize+8 ;calculate height of help gadgets
If HelpGadgets>0
helphigh+fsize+8 ;make the window tall enough
EndIf ;so the gadgets will fit too
cy$="Top" ;first face for cycle gadget
txlim.w=helpwide-22 ;limit of text printing width
;-------------------------------------------------------------------
LoadFont 0,font$,fsize ;load the font
Use IntuiFont 0
Screen 0,0,0,width,height,4,$29004,"Help Test Screen",1,0
AddIDCMP $400
Window 0,20,20,400,80,$10000,"Help Test",0,0
CatchDosErrs ;put requestors on our screen
Use Window 0
WindowFont 0
Activate 0
NPrint "Press HELP to toggle help window"
NPrint "Press ESC to Quit"
.mainloop
Repeat
ev.l=WaitEvent
If EventWindow=#HelpWindow ;the help window
If ev=$40 ;a gadget was pressed
If GadgetHit=52 ;selector cycle gad
ec=EventCode ;which face is up?
gt.w=links(ec) ;reset the GoTo line
If HelpGadgets=1
GTSetAttrs #HelpWindow,50,#GTLV_Top,gt;reset the listview
EndIf
EndIf
If GadgetHit=51 ;Go To gadget
GTSetAttrs #HelpWindow,50,#GTLV_Top,gt ;reset listview to selected line
EndIf
EndIf
If ev=$200 Then Gosub helppressed ;close gadget pressed
EndIf
If ev=$400 ;key pressed
a$=Inkey$
If a$=Chr$(27) ;ESC
Request "","Later...","Bye!"
split.b=1
EndIf
If a$=Chr$(139) ;Help key
Gosub helppressed ;toggle window open/closed
EndIf
EndIf
Until split=1
End
;--------------HELP WINDOW SUBROUTINE-----------------------------
;Toggles help window open/closed
;and loads in the text file the first time it is called
.helppressed
If HelpMe.b=Off
If helploaded.b=0 ;text not loaded yet
If Exists(help$) ;open the help doc
If ReadFile(0,help$)
ln=1
l.w=0
FileInput 0
While NOT Eof(0) AND l.w<maxlines
t$=Edit$(256)
check$=Left$(t$,1)
If check$="^" ;It's an INDEX!
t$=Mid$(t$,2) ;remove the character
lnk$(ln)=t$ ;save link title
cy$=cy$+"|"+lnk$(ln) ;add it to cycle gad
ln+1 ;increase link count
check$=";" ;and don't show this line
EndIf
If check$=">" ;A link points here!
t$=Mid$(t$,2)
t1$=t$
If Left$(t1$,1)="}" Then t1$=Mid$(t1$,2)
For i=0 To ln ;check the list
If t1$=lnk$(i) ;found it's match!
links(i)=l ;so update the array
EndIf
Next
EndIf
If Left$(t$,1)="}" ;Center this line!
t1$=Mid$(t$,2) ;chuck the }
t$=" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
chars.w=Len(t$)
Gosub getmax
t$=t1$
If Len(t$)<maxchars
t$=Centre$(t$,maxchars)
EndIf
EndIf
If check$<>";" ;throw out comment lines
Repeat
t1$="" ;word wrap routine *gulp*
chars.w=Len(t$) ;easy so far...
Gosub getmax
If chars>maxchars ;OH,NO!
For i=maxchars To 0 Step-1
If Mid$(t$,i,1)=" " ;look for a space
t1$=Mid$(t$,i+1) ;save the rest
t$=Left$(t$,i-1) ;trim t$
i=0 ;dump the loop
EndIf
Next i
EndIf
If AddItem (htxt()) ;add the line to the list
htxt()\text=t$
l+1
EndIf
If t1$<>"" Then t$=t1$ ;still more characters to add!
Until t1$="" ;keep going if more!
EndIf
Wend
CloseFile 0
helploaded=1
bw.w=(helpwide-8)/2
EndIf
Else
Request "Sorry...",help$+"|Not found."," OK "
helploaded=0
EndIf
EndIf
If helploaded=1
Gosub HelpGads
AddIDCMP $400000|$10|$400 ;need this for the arrows
Window #HelpWindow,helpx,helpy,helpwide,helphigh,$2|$8|$1000,"Help",1,0
AttachGTList #HelpWindow,#HelpWindow
GTSetAttrs #HelpWindow,50,#GTLV_Top,gt ;update the listview
SubIDCMP $400000|$10 ;to prevent possible problems
HelpMe=On
EndIf
Else
Use Window #HelpWindow
helpx=WindowX ;save current position
helpy=WindowY
Use Window 0 ;and shut the window
Activate 0
Free Window #HelpWindow
Free GTList #HelpWindow
HelpMe=Off
EndIf
Return
.getmax
maxchars=TextFit_(RastPort(0),&t$,chars,&al,0,1,txlim,fsize)
Return
.HelpGads
GTTags #GTLV_ReadOnly,True
GTListView #HelpWindow,50,0,0,helpwide-6,lvhigh,"",$10,htxt(),0,gt
If HelpGadgets =2
GTButton #HelpWindow,51,0,lvhigh-fsize+4,bw,hghigh,"Go To ->",0
GTCycle #HelpWindow,52,(helpwide-6)/2,lvhigh-fsize+4,bw,hghigh,"",0,cy$,ec
EndIf
If HelpGadgets=1
GTCycle #HelpWindow,52,0,lvhigh-fsize+4,helpwide-6,hghigh,"",0,cy$,ec
EndIf
Return